package proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class PersonBeanInvocationHandler implements InvocationHandler {

    private PersonBean personBean;

    public PersonBeanInvocationHandler(PersonBean personBean) {
        this.personBean = personBean;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        if (method.getName().equals("getName")) {
            System.out.println("setName not allowed!");
            return null;
        } else {
            return method.invoke(personBean, args);
        }
    }
}
